<template>
<div class="management-merchant views-container">
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link class="wlm-text" tag="span" :to="{path:'/merchant/managementMerchantAdd'}">
                <el-button size="small" type="primary">添加商家</el-button>
            </router-link>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="商家名称：" class="search">
                    <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.name" placeholder="请输入商家名称" style="width:160px;"></el-input>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button v-waves type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :default-sort="{prop: 'sort', order: 'descending'}" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column prop="sort" width="80" label="排序"  sortable>
                    <template slot-scope="scope">
                        <el-input-number @blur="changeTableItem({id:scope.row.id,sort:scope.row.sort},tableFormatData.userTable.change.sort)" style="width:100%;" size="mini" v-model="scope.row.sort" :controls="false"></el-input-number>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商家ID"  min-width="45">
                    <template slot-scope="scope">
                        <p>{{scope.row.id}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商家LOGO" >
                    <template slot-scope="scope">
                        <img class="logo" v-if="scope.row.logo" :src="scope.row.logo.file_path">
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商家名称" >
                    <template slot-scope="scope">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="name" label="销售额" >
                    <template slot-scope="scope">
                        <span>{{scope.row.salenum}}</span>
                    </template>
                </el-table-column> -->
                <el-table-column prop="name" label="商品数量" >
                    <template slot-scope="scope">
                        <router-link tag="span" :to="{path:'/merchandise/merchandiseManagement', query :{business_id: scope.row.id}}">
                            <span class="pointer">{{scope.row.goodsnum}}</span>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="门店数量" >
                    <template slot-scope="scope">
                        <router-link tag="span" :to="{path:'/merchant/storeListMerchant', query :{ bus_id:scope.row.id}}">
                            <span class="pointer">{{scope.row.storenum}}</span>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="店员数量" >
                    <template slot-scope="scope">
                        <router-link tag="span" :to="{path:'/merchant/merchantClerkList', query :{ bus_id:scope.row.id}}">
                            <span class="pointer">{{scope.row.menum}}</span>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="创建时间" >
                    <!-- |scope.row.creationtime -->
                    <template slot-scope="scope">
                        <span>{{scope.row.create_time}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作"  min-width="130">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/merchant/storeListMerchant', query :{ bus_id:scope.row.id}}">
                                <el-button type="text">门店</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <router-link class="wlm-text" tag="span" :to="{path:'/merchant/merchantClerkList', query :{ bus_id:scope.row.id}}">
                                <el-button type="text">店员</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <router-link class="wlm-text" tag="span" :to="{path:'/merchant/managementMerchantAdd', query :{ id:scope.row.id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row> -->
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
// import upload from '@/components/Upload/index'
import ChooseFiles from '@/components/ChooseFiles/index'
import {
  businessEdit,
  businessGet,
  businessDelete,
  businessIndex,
  businessSort
} from '@/api/merchant'
import waves from '@/directive/waves' // Waves directive
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'UserPlatform',
  components: {
    // upload,
    ChooseFiles
  },
  directives: {
    waves
  },
  data() {
    var checkImg = (rule, value, callback) => {
      const val = this.formFormatData.formData[rule.bindKey]
      const { message } = rule
      if (!Array.isArray(val) || (Array.isArray(val) && val.length === 0)) {
        return callback(new Error(`${message}！~`))
      } else {
        callback()
      }
    }
    return {
      chooseLogoConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'logo',
          model: 'img',
          validateField: 'merchantlog'
        }
      },
      chooseBgConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isMore: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'bgimg',
          model: 'img',
          validateField: 'businessbackgroundmap'
        }
      },
      choosePlatformConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 5,
          isMore: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'quaimg',
          model: 'img',
          validateField: 'businessqualification'
        }
      },
      formFormatData: {
        key: 'userForm',
        api: {
          editForm: {
            api: businessGet,
            params: {
              id: ''
            },
            filters: {
              img: {
                bindInit: ['chooseLogoConfig', 'chooseBgConfig', 'choosePlatformConfig']
              }
            }
          },
          submitForm: businessEdit
        },
        formData: {
          name: '',
          describe: '',
          logo: [],
          bgimg: [],
          quaimg: []
        },
        rules: {
          name: [{
            required: true,
            message: '请输入商家名称',
            trigger: 'blur'
          }],
          describe: [{
            required: true,
            message: '请输入商家介绍',
            trigger: 'blur'
          }],
          merchantlog: [{
            required: true,
            bindKey: 'logo',
            message: '请上传商家LOGO~!',
            validator: checkImg,
            trigger: 'change'
          }],
          businessbackgroundmap: [{
            required: true,
            bindKey: 'bgimg',
            message: '请上传商家背景图~!',
            validator: checkImg,
            trigger: 'change'
          }],
          businessqualification: [{
            required: true,
            bindKey: 'quaimg',
            message: '请上传商家资质~!',
            validator: checkImg,
            trigger: 'change'
          }]
        }
      },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: businessIndex,
            delList: businessDelete,
            msgConfig: {
              del: {
                type: 'warning',
                msg: '此操作会删除商家的所有数据，名下所有如有正在交易的商品，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
              }
            }
          },
          tableData: [],
          files: {
            name: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          change: {
            sort: {
              name: '排序',
              key: 'sort',
              api: businessSort
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
  }
}
</script>

<style lang="scss" scoped>
.management-merchant {
    .logo {
        height: 38px;
        width: 38px;
        border-radius: 38px;
        vertical-align: middle;
    }
}
</style>
